package cn.aiweiyi.qingjing.coupon.comm.exception;

import cn.aiweiyi.qingjing.coupon.comm.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 青衿
 * @Date 2020/11/14 15:43
 * 本项目全局的业务异常处理增强
 **/
@RestControllerAdvice
public class GlobalException {
    //定义一个异常处理器,对CouponException进行统一处理

    @ExceptionHandler(CouponException.class)
    public CommonResponse handleCouponException(
            HttpServletRequest request, CouponException e
    ) {
        CommonResponse<String> result = new CommonResponse<>(-1, "业务异常");
        result.setData(e.getMessage());
        return result;
    }
}
